package br.com.petsis.entity;

// Generated 18/05/2011 10:52:24 by Hibernate Tools 3.3.0.GA

import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PostLoad;
import javax.persistence.PostPersist;
import javax.persistence.PostRemove;
import javax.persistence.PostUpdate;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.validator.NotNull;
import org.jboss.seam.Component;

import br.com.petsis.enumerations.TipoOperacaoEnum;
import br.com.petsis.funcionalidades.auditoria.AuditoriaController;

/**
 * Pet generated by hbm2java
 */
@Entity
@Table(name = "mes_despesa")
public class MesDespesa implements java.io.Serializable {

	public static final Character STATUS_MES_DESPESA_ABERTO = 'A';
	public static final Character STATUS_MES_DESPESA_FECHADO = 'F';
	public static final Character STATUS_MES_DESPESA_REABERTO = 'R';
	
	private Integer idMesDespesa;
	private Integer mesRef;
	private Integer anoRef;
	private Float vlrTotalDespesas;
	private Character flgStatus;
	
	@Transient
	private TipoOperacaoEnum tipoOperacao;
	
	@Transient
	private String dadosAntigos;
	
	@PostLoad
	public void registrarDadosAntigos(){
		AuditoriaController auditoriaController = (AuditoriaController)Component.getInstance("auditoriaController");
		dadosAntigos = auditoriaController.recuperaDadosConcatenados(this);
	}
	
	@PostPersist
	@PostUpdate
	@PostRemove
	public void registrarAuditoria(){
		AuditoriaController auditoriaController = (AuditoriaController)Component.getInstance("auditoriaController");
		auditoriaController.registraLogAuditoria(this, tipoOperacao, dadosAntigos);
	}
	
	@PrePersist
	public void registrarTipoOperacaoInclusao(){
		tipoOperacao = TipoOperacaoEnum.INCLUSAO;
	}

	@PreRemove
	public void registrarTipoOperacaoExcluir(){
		tipoOperacao = TipoOperacaoEnum.EXCLUSAO;
	}
	
	@PreUpdate
	public void registrarTipoOperacaoAlteracao(){
		tipoOperacao = TipoOperacaoEnum.ALTERACAO;
	}
	
	public MesDespesa() {
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "ID_MES_DESPESA", unique = true, nullable = false)
	public Integer getIdMesDespesa() {
		return idMesDespesa;
	}

	public void setIdMesDespesa(Integer idMesDespesa) {
		this.idMesDespesa = idMesDespesa;
	}

	@Column(name = "mes_ref", nullable = false)
	@NotNull
	public Integer getMesRef() {
		return mesRef;
	}

	public void setMesRef(Integer mesRef) {
		this.mesRef = mesRef;
	}

	@Column(name = "ano_ref", nullable = false)
	@NotNull
	public Integer getAnoRef() {
		return anoRef;
	}

	public void setAnoRef(Integer anoRef) {
		this.anoRef = anoRef;
	}

	@Column(name = "vlr_total_despesas", nullable = true)
	public Float getVlrTotalDespesas() {
		return vlrTotalDespesas;
	}

	public void setVlrTotalDespesas(Float vlrTotalDespesas) {
		this.vlrTotalDespesas = vlrTotalDespesas;
	}

	@Column(name = "flg_status", nullable = false, length = 1)
	@NotNull
	public Character getFlgStatus() {
		return flgStatus;
	}

	public void setFlgStatus(Character flgStatus) {
		this.flgStatus = flgStatus;
	}

}
